package com.alen.sun.dao;

import com.alen.sun.bean.Category;
import com.alen.sun.bean.Room;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 分类
 */

@Mapper
public interface CategoryMapper {
    //添加分类
    @Insert("INSERT INTO category (categoryId, category_name) values (#{categoryId}, #{categoryName})")
    Boolean addCategory(Category category);

    //修改分类
    @Update("UPDATE category SET category_name = #{categoryName} where categoryId = #{categoryId}")
    Boolean updateCategory(Category category);

    //删除分类
    @Delete("DELETE FROM category where categoryId = #{categoryId}")
    Boolean deleteCategory(Category category);

    /**
     * 查询总记录数
     * @return
     */
    @Select("select count(*) from category")
    Long count();

    /**
     * 分页查询,获取列表数据
     * @param start
     * @param pageSize
     * @return
     */
    @Select("select * from category limit #{start},#{pageSize}")
    List<Category> page(Integer start, Integer pageSize);


    //批量删除分类
    @Delete({
            "<script>",
            "delete from category where categoryId in",
            "<foreach item='id' collection='ids' open='(' separator=',' close=')'>#{id}</foreach>",
            "</script>"
    })
    Boolean deleteByIds(List<String> ids);

    //根据分类名称查找分类--判断是否存在
    @Select("SELECT count(*) FROM category WHERE category_name = #{categoryName}")
    Integer selectByName(Category category);

    //查找分类根据Id
    @Select("SELECT count(*) FROM category WHERE categoryId = #{categoryId}")
    Integer selectByCategoryId(String categoryId);

    @Select("select * from category")
    List<Category> list();

    @Select("select * from category where category_name like #{searchName}")
    List<Category> word(String searchName);
}
